package pk.nak.responses;

import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import pk.nak.data.EatOut;
import pk.nak.data.EatOutMenuItemPrices;
import pk.nak.utils.XMLUtils;

public class ComparePriceResponse extends BaseResponse {

	public EatOutMenuItemPrices eomip;
	@Override
	public void onSuccess(String response) {
		try{
			this.response = response;
			DocumentBuilderFactory dbfLoginResponse = DocumentBuilderFactory.newInstance();
	        DocumentBuilder dbLoginResponse = dbfLoginResponse.newDocumentBuilder();
	        
	        Document dom = dbLoginResponse.parse(new InputSource(new StringReader(response)));
	        NodeList nl = dom.getElementsByTagName("item");
	        
	        this.eomip = new EatOutMenuItemPrices("", "");
	        
	        if ( nl != null && nl.getLength() > 0 ){
	        	 for ( int i = 0 ; i < nl.getLength(); i ++){
	        		Element eleDish = (Element)nl.item(i);

	   				String dishname = XMLUtils.getTextValue(eleDish, "title");
	   				String dishprice = XMLUtils.getTextValue(eleDish, "price");
	        		this.eomip.addPriceGroup(new EatOut("", dishname, "", "", "", "", "", "", 0,0,0), Double.parseDouble(dishprice));
	        	}
	        }
		}catch(Exception ex){
			
		}
	}

}
